<?php 
namespace Admin\Controller;
use Think\Controller;

class LoginController extends Controller{
	public function login(){
			if(IS_GET){
			$this->display();
		}else{
			//接收验证码进行比对
			$captcha =I('post.captcha');
			// dump($caotcha);die;
			$verify = new \Think\Verify();
			$res=$verify->check($captcha);
			//dump($res);die;


//先屏蔽验证码
/*
			if(!$res){
				$this->error('验证码不正确');				
			}
*/
			//接收用户密码调用模型方法进行比对
			$username = I('post.username');
			$password = I('post.password');
			$model=D('Admin');
			$res = $model->login($username,$password);
			if(!$res){
				$this->error($model->getError());
			}else {
				$this->success('登录成功', U('Index/index'));
			}
		}
	}
	
	//生成验证码
	public function verify(){
		//如果gd库页开启了但是就是不能正常的生成验证码可以使用ob_clean()实现
		$config = array('length'=>3);
		$verify = new \Think\Verify($config);
		$verify->entry();
	}

}